import 'package:cached_network_image/cached_network_image.dart';
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    ProfileState state, Dispatch dispatch, ViewService viewService) {
  return new Scaffold(
      appBar: new AppBar(
          centerTitle: true,
          elevation: 2.0,
          title: new Text(
            "设置",
            style: TextStyle(color: Colors.black54, fontSize: 18),
          )),
      body: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Card(
            key: null,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10.0),
            ),
            margin: EdgeInsets.all(20),
            child: new Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  margin: EdgeInsets.only(left: 10),
                  height: 54.0,
                  child: ListTile(
                    title: new Text('更换头像'),
                    trailing: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        CachedNetworkImage(
                          width: 60,
                          height: 60,
                          placeholder: (context, url) =>
                              CircularProgressIndicator(),
                          errorWidget: (context, url, error) =>
                              Image.asset("assets/images/user.png"),
                          imageUrl:
                              GlobalState.baseUrl(state.userInfo['headImage']),
                        ),
                        ImageIcon(
                          AssetImage("assets/images/right.png"),
                          size: 24.0,
                        )
                      ],
                    ),
                    onTap: () =>
                        dispatch(ProfileActionCreator.onChangeAvatar()),
                  ),
                ),
                new Divider(
                  height: 1,
                  indent: 28,
                ),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  height: 54.0,
                  child: ListTile(
                    title: new Text('姓名'),
                    trailing: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Text(state.userInfo['name']),
                        ImageIcon(
                          AssetImage("assets/images/right.png"),
                          size: 24.0,
                        ),
                      ],
                    ),
                    onTap: () => dispatch(ProfileActionCreator.onChangeName()),
                  ),
                ),
                new Divider(
                  height: 1,
                  indent: 28,
                ),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  height: 54.0,
                  child: ListTile(
                    title: new Text('修改密码'),
                    trailing: ImageIcon(
                      AssetImage("assets/images/right.png"),
                      size: 24.0,
                    ),
                    onTap: () =>
                        dispatch(ProfileActionCreator.onChangePassword()),
                  ),
                ),
                new Divider(
                  height: 1,
                  indent: 28,
                ),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  height: 54.0,
                  child: ListTile(
                    title: new Text('手机号'),
                    trailing:
                        Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
                      Text(state.userInfo['mobile']),
                      ImageIcon(
                        AssetImage("assets/images/right.png"),
                        size: 24.0,
                      ),
                    ]),
                    onTap: () =>
                        dispatch(ProfileActionCreator.onChangeMobile()),
                  ),
                ),
                new Divider(
                  height: 1,
                  indent: 28,
                ),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  height: 54.0,
                  child: ListTile(
                    title: new Text('护眼模式'),
                    trailing:
                        Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
                      CupertinoSwitch(
                        value: state.darkOn,
                        onChanged: (bool val) {
                          dispatch(ProfileActionCreator.onDark());
                        },
                      ),
                    ]),
                  ),
                ),
                new Divider(
                  height: 1,
                  indent: 28,
                ),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  height: 54.0,
                  child: ListTile(
                    title: new Text('注销账号'),
                    trailing:
                        Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
                      ImageIcon(
                        AssetImage("assets/images/right.png"),
                        size: 24.0,
                      ),
                    ]),
                    onTap: () => dispatch(ProfileActionCreator.onDestroy()),
                  ),
                ),
//          new Divider(
//            height: 1,
//            indent: 28,
//          ),
//          Container(
//            margin: EdgeInsets.only(left: 10),
//            height: 54.0,
//            child: ListTile(
//              title: new Text('性别'),
//              trailing: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
//                Text(state.userInfo['sex'] == 'male' ? '男' : '女'),
//                ImageIcon(
//                  AssetImage("assets/images/right.png"),
//                  size: 24.0,
//                ),
//              ]),
//              onTap: () => dispatch(ProfileActionCreator.onChangeGander()),
//            ),
//          ),
              ],
            ),
          ),
          SizedBox(height: 10),
          Container(
              child: RaisedButton(
            onPressed: () => dispatch(ProfileActionCreator.onLogout()),
            colorBrightness: Brightness.dark,
            child: Text("退出登录", style: new TextStyle(color: Colors.black)),
          )),
        ],
      ));
}
